<?
require_once  '../classes/TestStudentiDataManager.php';
require_once  '../classes/TestDataManager.php';
require_once  '../classes/ConnectionDB.php';

$connection =ConnectionDB::getInstance()->connectToDB();

$nomeTest=$_GET["nomeTest"];
$codiceTest = $_GET["codiceTest"];
$ore = $_GET["ore"];
$minuti = $_GET["minuti"];
$key=$_GET["key"];
$classe=$_GET["classe"];

$listaDomande = TestDataManager::getInstance()->searchDomandeByCodiceTest($connection, $codiceTest);
$listaLink = array();

$flag = FALSE;
for($i=0; $i<count($listaDomande) && $flag==FALSE; $i++)
{
    if($listaDomande[$i]->getLink()!="")
        $listaLink[] = $listaDomande[$i]->getLink();
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Download Test PDF</title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">
            @import url("../css/style.css");

            #testForm {
                padding-top: 3%;
                margin-left: -5px;
            }

            #testFormCont
            {
                padding-left: 2%;
                padding-top: 3%;
            }

            #testFormCont table
            {

            }


        </style>
        <script type="text/javascript">
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            var listaDomande;
            var numItem=10;
            var currentIndex=0;

            window.onload = function()
            {
                var testForm = new GlassBox();
                testForm.init( 'testForm', '840px', '390px', 'auto','',true, false);
                testForm.ipos();
                testForm.appear();
            }

            function downloadPDF()
            {
                document.getElementById('codiceTestPdf').value=<?= $codiceTest ?>;
                document.getElementById('nomeTestPdf').value='<?= $nomeTest ?>';
                document.getElementById('orePdf').value=<?= $ore ?>;
                document.getElementById('minutiPdf').value=<?= $minuti ?>;
                document.getElementById('keyPdf').value='<?= $key ?>';
                document.getElementById('classePdf').value=<?= $classe ?>;
                document.getElementById('operationPdf').value='makeTestPdf';

                document.getElementById('formPdf').submit();
            }
        </script>
    </head>
    <body>
        <?php include '../portal/header.php';?>
        <form id="formPdf" method="POST" action="newTestListener.php">
            <input type="hidden" id="codiceTestPdf" name="codiceTest" value="" />
            <input type="hidden" id="nomeTestPdf" name="nomeTest" value="" />
            <input type="hidden" id="orePdf" name="ore" value="" />
            <input type="hidden" id="minutiPdf" name="minuti" value="" />
            <input type="hidden" id="keyPdf" name="key" value="" />
            <input type="hidden" id="classePdf" name="classe" value="" />
            <input type="hidden" id="operationPdf" name="operation" value="" />
        </form>

        <center>
            <div id="testForm">
                <div id="testFormCont">
                    <center><h3>Scarica i file allegati...saranno usati nelle domande del test</h3></center>
                    <table border="1">
                        <tr>
                            <th>Num allegato</th>
                            <th>Link</th>
                        </tr>
                        <? $ind=0;
                        for($i=0;$i<count($listaLink);$i++)
                        {
                            $link = $listaLink[$i];
                            $tmp = explode("/", $link);
                            $nomefileStored = $tmp[count($tmp)-1];
                            $ind++;
                            ?>
                        <tr>
                            <td style="text-align: center"><?= $ind ?></td><td><a href="<?= $link?>"><?= $nomefileStored ?></a></td>
                        </tr>
                         <?}?>
                    </table>
                    <br /><br />
                       

                    <input type="button" value="Scarica PDF test" onclick="javascript:downloadPDF()"/>


                </div>
            </div>
        </center>
    </body>
</html>
